import { MenuResponse } from "@/types";
let currentJob: Promise<MenuResponse> | null;
export function getMenus() {
  if (currentJob) {
    return currentJob;
  }
  const job: Promise<MenuResponse> = new Promise((reslove) => {
    // let localMenu = getLocalMenu();
    let localMenu = getSideMenu();
    if (localMenu) {
      // @ts-ignore
      return reslove(localMenu);
    }
  });
  currentJob = job;
  job.finally(() => {
    currentJob = null;
  });
  return job;
}

const getSideMenu = () => {
  const currentMenu = [
    {
      icon: "icon_home",
      keepAlive: "false",
      key: "customer_public",
      // menu_id: 2,
      // order: 2,
      parentKey: "",
      path: "/public-customer",
      title: "公海管理",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "customer_public_index",
      // menu_id: 2,
      // order: 2,
      parentKey: "customer_public",
      path: "/index",
      title: "公司公海",
    },
    {
      icon: "icon_MTR",
      keepAlive: "false",
      key: "operate",
      // menu_id: 2,
      // order: 2,
      parentKey: "",
      path: "/operate",
      title: "运营管理",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "dispatch",
      // menu_id: 2,
      // order: 2,
      parentKey: "operate",
      path: "/dispatch",
      title: "派单设置",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "receive",
      parentKey: "operate",
      path: "/receive",
      title: "接单设置",
      permission: ["role.rock.dept.admin"]
    },
    {
      icon: "icon_edit",
      keepAlive: "false",
      key: "customer",
      // menu_id: 2,
      // order: 2,
      parentKey: "",
      path: "/customer",
      title: "客户管理",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "myCustomer",
      // menu_id: 2,
      // order: 2,
      parentKey: "customer",
      path: "/index",
      title: "我的客户",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "allCustomer",
      parentKey: "customer",
      path: "/all",
      title: "全部客户",
      permission: ["role.rock.dept.admin"]
    },
    {
      icon: "icon_menu",
      keepAlive: "false",
      key: "business",
      // menu_id: 2,
      // order: 2,
      parentKey: "",
      path: "/business",
      title: "业务管理",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "business_invitation",
      // menu_id: 2,
      // order: 2,
      parentKey: "business",
      path: "/invitation",
      title: "邀约",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "business_visit",
      // menu_id: 2,
      // order: 2,
      parentKey: "business",
      path: "/visit",
      title: "上门",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "business_signed",
      // menu_id: 2,
      // order: 2,
      parentKey: "business",
      path: "/signed",
      title: "签单",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "business_loan",
      // menu_id: 2,
      // order: 2,
      parentKey: "business",
      path: "/loan",
      title: "放款",
    },
    {
      icon: "icon_addresslist",
      keepAlive: "false",
      key: "framework",
      // menu_id: 2,
      // order: 2,
      parentKey: "",
      path: "/framework",
      title: "组织架构",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "member",
      // menu_id: 2,
      // order: 2,
      parentKey: "framework",
      path: "/member",
      title: "员工管理",
    },
    {
      icon: "icon_setting",
      keepAlive: "false",
      key: "setting",
      // menu_id: 2,
      // order: 2,
      parentKey: "",
      path: "/setting",
      title: "系统设置",
    },
    {
      icon: "",
      keepAlive: "false",
      key: "log",
      // menu_id: 3,
      // order: 3,
      parentKey: "setting",
      path: "/log",
      title: "操作日志",
    },
  ];

  return currentMenu;
};
